import re

from fontTools.misc import etree

import requests

# 人机校验
g_sessionID = ""
g_steamID = ""
# 请求延迟
defaultReqDelay = 0.1

uaHeader = {
    "user-agent": " Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0".replace(
        ' ', "")
}
# 获取sessionId
try:
    res = requests.get("https://steamcommunity.com/", headers=uaHeader)
    print("初始化参数")
except:
    print("初始化参数失败")
# print(res)
e = etree.HTML(res.text)
script = e.xpath('//script//text()')
for i in script:
    if "g_sessionID" in i:
        for h in re.compile(r'g_sessionID\s*=\s*[^;]+;').findall(i):
            g_sessionID = h.replace(' "', "").replace('";', "").split("=")[1]
        for g in re.compile(r'g_steamID\s*=\s*[^;]+;').findall(i):
            g_steamID = g.replace(' "', "").replace('";', "").split("=")[1]
